package com.yunqing.restkeeper.enterprise.web.controller;

import com.yunqing.restkeeper.common.constants.SystemCode;
import com.yunqing.restkeeper.common.utils.Result;
import com.yunqing.restkeeper.common.utils.ResultCode;
import com.yunqing.restkeeper.enterprise.web.vo.LoginVO;
import com.yunqing.restkeeper.operator.api.service.IEnterpriseAccountService;
import com.yunqing.restkeeper.shop.api.service.IStoreManagerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName LoginController
 * @Description TODO
 * @author: puyunqing
 * @Date: 2025/7/1
 */
@RestController
@Slf4j
@Tag(name = "登录接口")
public class LoginController {

    @DubboReference(version = "1.0.0", check = false)
    private IEnterpriseAccountService enterpriseAccountService;

    @DubboReference(version = "1.0.0", check = false)
    private IStoreManagerService storeManagerService;

    @Operation(summary = "登录入口")
    @PostMapping("/login")
    public Result login(@RequestBody LoginVO loginVO) {

        if (SystemCode.USER_TYPE_SHOP.equals(loginVO.getType())) {
            //集团用户
            return enterpriseAccountService.login(loginVO.getShopId(), loginVO.getPhone(), loginVO.getPassword());
        }

        if (SystemCode.USER_TYPE_STORE_MANAGER.equals(loginVO.getType())) {
            //店长
            return storeManagerService.login(loginVO.getShopId(), loginVO.getPhone(), loginVO.getPassword());
        }

        Result result = new Result();
        result.setStatus(ResultCode.error);
        result.setDesc("不支持当前用户类型登录");
        return result;

    }
}
